<?php
namespace App\Controller;

use Think\Controller;
use Think\Exception;

class LinuxController extends Controller
{

    //检测用户证件
    public function userCert()
    {
        $userCerts = M('UserCert')->where(['is_expired' => 0])->field('end_time,user_id,name,id')->select();
        if ($userCerts) {
            $time = strtotime('+30 days');
            foreach ($userCerts as $userCert) {
                if ($userCert['end_time'] <= $time) {
                    //开启事务
                    M('Message')->startTrans();
                    try {
                        //插入信息表
                        $title = '您的' . $userCert['name'] . '证件已到期';
                        $result = lt_add_message($title, $title, $userCert['user_id']);
                        if ($result === false) {
                            throw new Exception('插入信息表失败！');
                        }
                        //更改用户证件状态
                        $result = M('UserCert')->where(['id' => $userCert['id']])->save(['is_expired' => 1]);
                        if ($result === false) {
                            throw new Exception('更改用户证件状态失败！');
                        }
                        M('Message')->commit();
                    } catch (Exception $e) {
                        M('Message')->rollback();
                    }
                }
            }
        }
    }

/*    //审核用户
    public function checkBusiness()
    {
        $businesses = M('Business')->where(['is_checked' => 0])->select();
        $time = strtotime('-15 minutes');
        if ($businesses) {
            foreach ($businesses as $business) {
                if ($business['checking_time'] <= $time) {
                    $result = M('Business')->where(['id' => $business['id']])->save(['is_checked' => 1]);
                    if ($result !== false) {
                        lt_send_sms($business['phone'], '【一号点评】您的商户审核已通过');
                    }
                }
            }
        }
    }*/
}